using System;
using System.Collections.Generic;
using System.Text;
using QLPMT_DTO;
using QLPMT_DAO;

namespace QLPMT_BUS
{
   public class HoaDonBUS
    {
       public string GetMaHoaDon()
       {
           List<HoaDon> list=new List<HoaDon>();
           list = new HoaDonDAO().GetALL();
           HoaDon temp=new HoaDon();
           foreach (HoaDon X in list)
           {
               temp.Mahoadon = X.Mahoadon;
           }
           string ma = "";
           if (temp.Mahoadon != null)
           {
               char[] chuoi = temp.Mahoadon.ToCharArray(2, temp.Mahoadon.Length - 2);
               string chuoima = "";
               foreach (char charX in chuoi)
               {
                   chuoima = chuoima + charX;
               }
               int soluonghoadon = int.Parse(chuoima) + 1;
               ma = "HD" + soluonghoadon.ToString();
           }
           else
               ma = "HD1";
           return ma;
       }
       // Them 1 hoa don moi
       public Boolean InsertHoaDon(string maphieukham, double tienthuoc, double thanhtien)
       {
           try
           {
               string ma = GetMaHoaDon();
               HoaDon dto = new HoaDon(ma, maphieukham, tienthuoc, thanhtien);
               new HoaDonDAO().InsertHoaDon(dto);
           }
           catch
           {
               return false;
           }
           return true;
       }
    }
}
